package com.xuetang9.fujian.socketdemo.tcpdemo.onetomore;

import java.io.File;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.util.Scanner;

/**
 * @author: fujian
 * @description:
 * @date: 2021/5/10 9:40
 * @version: V1.0
 * @package: com.xuetang9.fujian.socketdemo.tcpdemo.onetomore
 **/
public class AIClient {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        Scanner scanner = new Scanner(System.in);
        Socket socket = new Socket("localhost",9527);
        System.out.println("成功连接到服务端");

        ObjectOutputStream outStream = new ObjectOutputStream(socket.getOutputStream());
        ObjectInputStream inStream = new ObjectInputStream(socket.getInputStream());

        while (true){
            System.out.println("想和小爱同学说些什么：");
            String command = scanner.next();
            outStream.writeObject(command);
            outStream.flush();
            if ("bye".equals(command)) break;
            Object object = inStream.readObject();
            if (object instanceof File){
//                new Thread(new MusicTask(CommandStore.ReplyMap.get(object))).start();
                System.out.println("播放音乐");
            }else {
                System.out.println("接收到来自小爱同学的消息：" + object);
            }
        }

        inStream.close();
        outStream.close();
        socket.close();

    }
}
